#!/bin/bash
set -uo pipefail

SCRIPT_DIR=$(realpath $(dirname $0))
PROJ_DIR=$(realpath $SCRIPT_DIR/..)
BIN=$PROJ_DIR/target/debug/main
TEST_OUTPUT_DIR=$PROJ_DIR/target/test_output
TEST_CASE_DIR=$PROJ_DIR/test

mkdir -p $TEST_OUTPUT_DIR

function test_file {
  FILE_NAME=$1
  echo "Test $FILE_NAME => $TEST_OUTPUT_DIR/$FILE_NAME.log"
  $BIN $TEST_CASE_DIR/$FILE_NAME.sy 2> $TEST_OUTPUT_DIR/$FILE_NAME.log
  diff $TEST_CASE_DIR/${FILE_NAME}_truth.log $TEST_OUTPUT_DIR/$FILE_NAME.log
  if [[ $? != 0 ]]; then
    echo "Failed"
    exit 1
  fi
}

test_file sample1
test_file sample2
test_file sample3
test_file sample4
